package com.ts.enterprise.enums;

import lombok.Getter;

/**
 * @Author Administrator
 * @Date 2021/10/18 13:42
 * @Description
 */
@Getter
public enum ApiCode {
    /**
     * 操作成功
     **/
    SUCCESS(200, "操作成功"),
    /**
     * 非法访问
     **/
    UNAUTHORIZED(403, "非法访问"),

    MISSING_PARAM(1001,"缺失参数："),
    /**
     * HTTP请求方式错误
     */
    HTTP_REQUEST_METHOD_NOT_SUPPORTED(1002,"HTTP请求方式错误，仅支持："),
    /**
     * 参数错误
     */
    ERROR_PARAM(1003,"参数错误：",true),

    /**
     * 数据库执行错误
     */
    DATABASE_EXECUTION_ERROR(1004,"数据库执行错误"),


    OSS_TOKEN_FAIL(1005,"oss移动端token获取失败"),

    SMS_INVALID_MOBILE_NUMBER(1006, "手机号码不正确"),

    SMS_SEND_FAIL(1007,"发送短信失败"),

    STOCK_SHEET_STATUS_INCORRECT(1100, "单子状态不正确"),

    WORKDAY_REPEAT(1101, "打卡工作日重复"),

    MUST_REPEAT(1102, "必须打卡日期重复"),

    NOT_REPEAT(1103, "不用打卡日期重复"),

    MUST_NOT_CONFLICT(1104, "必须打卡和不用打卡日期冲突"),

    TYPE_NOT_MATCH(1105, "打卡时间和打卡类型不匹配"),

    MORNING_EVENING_RULE_EMPTY(1106, "早晚打卡规则不能为空"),

    MORNING_EVENING_MORNING_EMPTY(1107, "早晚打卡上班时间不能为空"),

    MORNING_EVENING_EVENING_EMPTY(1107, "早晚打卡下班时间不能为空"),

    MORNING_GREATER_THAN_EVENING(1107, "早晚打卡下班时间必须大于上班时间"),

    MORNING_EVENING_REST_START_EMPTY(1107, "早晚打卡休息开始时间不能为空"),

    MORNING_EVENING_REST_END_EMPTY(1107, "早晚打卡休息结束时间不能为空"),

    MORNING_EVENING_REST_START_GREATER_THAN_END(1107, "早晚打卡休息结束时间必须大于休息开始时间"),

    MORNING_EVENING_START_GREATER_THAN_REST(1107, "早晚打卡休息开始时间必须大于上班时间"),

    MORNING_EVENING_REST_GREATER_THAN_END(1107, "早晚打卡休息结束时间必须大于下班时间"),

    MORNING_EVENING_TIME_FORMAT_EXCEPTION(1107, "早晚打卡时间格式不正确",true),

    PART_RULE_EMPTY(1107, "分段打卡时间段不能为空"),

    ;

    private final int code;
    private Integer logicCode = 0;
    private final String message;

    ApiCode(final int code, final String message, Boolean logic) {
        this.code = code;
        this.message = message;
        this.logicCode = logic?1:0;
    }

    ApiCode(int code,  String message) {
        this.code = code;
        this.message = message;
    }

    public static ApiCode getApiCode(int code) {
        ApiCode[] ecs = ApiCode.values();
        for (ApiCode ec : ecs) {
            if (ec.getCode() == code) {
                return ec;
            }
        }
        return SUCCESS;
    }

    public int getCode() {
        return code;
    }

    public String getMessage() {
        return message;
    }
}
